//
//  LTConnecUsViewController.m
//  Learn
//
//  Created by zyl_macbookpro on 2024/4/1.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "LTConnecUsViewController.h"
#import "LTMineAPIManager.h"
@interface LTConnecUsViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic ,strong)UITableView *tableView;

@property(nonatomic ,strong)NSArray *titleArray;

@property(nonatomic ,strong)NSString *educationConsultant;

@property(nonatomic ,strong)NSString *educationMobile;

@property(nonatomic ,strong)NSString *mobile;

@end

@implementation LTConnecUsViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self renderNavBarWithBackgroundImage:[UIImage imageWithColor:LTClearColor] backgroundColor:LTClearColor shadowColor:nil textAttributeDic:@{NSForegroundColorAttributeName:rgba(0, 0, 0, 1),NSFontAttributeName:MFontWithSize(17)} enableScrollEdgeAppearance:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"联系我们";
    // Do any additional setup after loading the view.
    [self setBackButtonIsHidden:NO];
    [self.view addSubview:self.tableView];
    
    self.tableView.height = self.titleArray.count *55+10;
    [LTMineAPIManager getConnectInfoWithParam:@{} result:^(NSDictionary * _Nonnull dic) {
        
        NSDictionary *data = dic[@"data"];
        self.educationConsultant = data[@"education_consultant"];
        self.educationMobile = data[@"education_mobile"];
        self.mobile = data[@"mobile"];
        [self.tableView reloadData];
    }];
    
}
#pragma mark -UITableViewDelegate,UITableViewDelegate
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@""];
        //cell.selectionStyle =UITableViewCellSelectionStyleNone;
    }
    [cell removeAllSubviews];
    UILabel *detailTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(LTScreenWidth/2.0 - 16, 0, LTScreenWidth/2.0 - 36, 58)];
    detailTextLabel.textAlignment = NSTextAlignmentRight;
    UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, LTScreenWidth/2.0 - 36, 58)];
    detailTextLabel.textColor = LTTextBlack;
    if ([self.titleArray[indexPath.row] isEqualToString:@"客服电话"]) {
        
        detailTextLabel.text = self.educationMobile;
        
    }
    if ([self.titleArray[indexPath.row] isEqualToString:@"教育顾问"]) {
        detailTextLabel.text = self.educationConsultant;
    }
    if ([self.titleArray[indexPath.row] isEqualToString:@"联系电话"]) {
        detailTextLabel.text = self.mobile;
    }
    textLabel.text = self.titleArray[indexPath.row];
    textLabel.font = MFontWithSize(15);
    textLabel.textColor = LTTextBlack;
    detailTextLabel.font = RFontWithSize(15);
    [cell addSubview:textLabel];
    [cell addSubview:detailTextLabel];
    return cell;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.titleArray.count;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 58;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.titleArray[indexPath.row] isEqualToString:@"客服电话"]) {
        
     //   [MethodTool callWithMobileNumber:lApp.mobileCustomer];
        
    }
    
}
#pragma mark -getters and setters
-(UITableView *)tableView{
    if (!_tableView){
        _tableView =[[UITableView alloc] initWithFrame:CGRectMake(16, LTTopBarHeight + 16, LTScreenWidth - 32, LTScreenHeight - LTTopBarHeight) style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        _tableView.bounces = NO;
        [_tableView setBackgroundColor:LTWhiteColor];
        [_tableView setSeparatorColor:LTSeparatorColor];
        [_tableView setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        _tableView.layer.cornerRadius = 12;
        _tableView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:50/255.0 blue:83/255.0 alpha:0.0500].CGColor;
        _tableView.layer.shadowOffset = CGSizeMake(0,2);
        _tableView.layer.shadowOpacity = 1;
        _tableView.layer.shadowRadius = 12;

    }
    
    return _tableView;
}

- (NSArray *)titleArray
{
    if (!_titleArray) {
        _titleArray = @[@"教育顾问",@"联系电话",@"客服电话"];
    }
    return _titleArray;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
